package com.liangzhong.modules.ninehalf.command
{
	import com.common.utils.Debug;
	import com.liangzhong.constants.ApplicationConstants;
	import com.liangzhong.constants.NotificationConstants;
	import com.liangzhong.model.AppData;
	import com.liangzhong.model.GameStatus;
	import com.liangzhong.model.ninehalf.vo.Bet;
	import com.liangzhong.model.ninehalf.vo.GameEnd;
	import com.liangzhong.model.ninehalf.vo.HostGold;
	import com.liangzhong.model.ninehalf.vo.NineHalfPlayer;
	import com.liangzhong.model.ninehalf.vo.NineHalfResult;
	import com.liangzhong.model.ninehalf.vo.NineHalfTableInfo;
	import com.liangzhong.model.ninehalf.vo.OpenCard;
	import com.liangzhong.model.ninehalf.vo.SelectFirstCard;
	import com.liangzhong.model.ninehalf.vo.SelectHost;
	import com.liangzhong.model.ninehalf.vo.StartDisCard;
	import com.liangzhong.modules.ninehalf.mediator.NineHalfMediator;
	import com.liangzhong.proxy.ninehalf.NineHalfProxy;
	
	import org.puremvc.as3.interfaces.INotification;
	import org.puremvc.as3.patterns.command.SimpleCommand;

	/**
	 * NineHalf 处理
	 * @author lxh
	 * 
	 */	
	public class NineHalfCommand extends SimpleCommand
	{
		public function NineHalfCommand()
		{
			super();
		}
		override public function execute(notification:INotification):void
		{
			var nineHalfProxy :NineHalfProxy = facade.retrieveProxy(NineHalfProxy.ProxyName) as NineHalfProxy;
			var retCode :int;
			var betNum :int
			var userId :int = AppData.getInstance().user.userID;
			var nineHalfTableInfo :NineHalfTableInfo;
			var nineHalfPlayer :NineHalfPlayer;
			//var interactiveData :InteractiveData;
			var pos :int ;
			//var chat :Chat
			switch(notification.getName())
			{
				case ApplicationConstants.NineHalf_userReady://用户开始
				{
					nineHalfProxy.userReady(userId);
					AppData.getInstance().nineHalfGame.nineHalfPlayers = [];
					Debug.echo("NineHalf---》ready req userId = " + userId,Debug.TRACER);
					break;
				}
				case NineHalfProxy.UserReady_Result://开始反馈
				{
					///设定状态
					AppData.getInstance().nineHalfGame.gameStatus = GameStatus.GameReady;
					nineHalfTableInfo = notification.getBody() as NineHalfTableInfo;
					nineHalfTableInfo.userId = userId;
					AppData.getInstance().nineHalfGame.curPos = nineHalfTableInfo.tablePos;
					AppData.getInstance().nineHalfGame.nineHalfTableInfo = nineHalfTableInfo;
					Debug.echo("NineHalf---》ready res pos = "+ nineHalfTableInfo.tablePos,Debug.TRACER);
					Debug.echo(nineHalfTableInfo,Debug.TRACER);
					this.sendNotification(NineHalfMediator.NineHalf_Game_Ready_Success);
					break;
				}
				case NineHalfProxy.UserEnterTable_Result://用户进入桌子
				{
					nineHalfPlayer = notification.getBody() as NineHalfPlayer;
					//retCode = nineHalfPlayer.retCode;
					AppData.getInstance().nineHalfGame.addPlayer(nineHalfPlayer);
					Debug.echo("NineHalf ---》user enter table res",Debug.TRACER);
					Debug.echo("userId = " + nineHalfPlayer.uid+"  pos = "+nineHalfPlayer.tablePos,Debug.TRACER);
					this.sendNotification(NineHalfMediator.NineHalf_User_Enter_Table,nineHalfPlayer);
					break;
				}
				case NineHalfProxy.SelectHost_Result://选庄
				{
					AppData.getInstance().user.gameStatus = GameStatus.GameStart;
					var selectHost :SelectHost = notification.getBody() as SelectHost;
					Debug.echo("NineHalf---》select host res",Debug.TRACER);
					Debug.echo("point = "+selectHost.fPoint+","+selectHost.sPoint+" pos = "+selectHost.tablePos,Debug.TRACER);
					this.sendNotification(NineHalfMediator.NineHalf_Select_Host,selectHost);
					break;
				}
				case ApplicationConstants.NineHalf_SelectHostGold://选庄金
				{
					Debug.echo("NineHalf---》select host gold req",Debug.TRACER);
					betNum = notification.getBody().betNum;
					nineHalfProxy.selectHostGold(userId,betNum);
					break;
				}
				case NineHalfProxy.NineHalf_SelectHostGold_Result://选庄金结果
				{
					Debug.echo("NineHalf---》select host gold res",Debug.TRACER);
					var hostGold :HostGold = notification.getBody() as HostGold;
					this.sendNotification(NineHalfMediator.NineHalf_Select_Host_Gold,hostGold);
					break;
				}
				case NineHalfProxy.SelectFirstCard_Result://选首发牌
				{
					AppData.getInstance().user.gameStatus = GameStatus.GameStart;
					var selectFcard :SelectFirstCard = notification.getBody() as SelectFirstCard;
					Debug.echo("NineHalf---》select first dis card res",Debug.TRACER);
					Debug.echo("point = "+selectFcard.fPoint+","+selectFcard.sPoint+" pos = "+selectFcard.tablePos,Debug.TRACER);
					this.sendNotification(NineHalfMediator.NineHalf_Select_First_Card,selectFcard);
					break;
				}
				case NineHalfProxy.StartDisCard_Result://发牌
				{
					var startDisCard :StartDisCard = notification.getBody() as StartDisCard;
					Debug.echo("NineHalf---》display card res");
					Debug.echo("data:"+startDisCard.posTags,Debug.TRACER);
					this.sendNotification(NineHalfMediator.NineHalf_StartDis_Card,startDisCard);
					break;
				}
				case NineHalfProxy.TrunBet_Result://轮到下注
				{
					var betPos :int = notification.getBody() as int;
					Debug.echo("NineHalf---》turn bet res pos = "+betPos,Debug.TRACER);
					this.sendNotification(NineHalfMediator.NineHalf_TrunBet,betPos);
					break;
				}
				case ApplicationConstants.NineHalf_Bet://用户下注
				{
					betNum = notification.getBody().betNum;
					var isQiu :int = notification.getBody().isQiu;
					nineHalfProxy.bet(userId,isQiu,betNum);
					Debug.echo("NineHalf---》user bet req,betNum = " + betNum+",isQiu = "+isQiu,Debug.TRACER);
					break;
				}
				case NineHalfProxy.Bet_Result://下注结果
				{
					var bet :Bet = notification.getBody() as Bet;
					Debug.echo("NineHalf---》user bet res ："+bet,Debug.TRACER);
					this.sendNotification(NineHalfMediator.NineHalf_Bet,bet);
					break;
				}
				case NineHalfProxy.OpenCard_Result://开牌
				{
					///
					if(AppData.getInstance().user.gameStatus == GameStatus.GameStart)
					{
						AppData.getInstance().user.isShowBalance = false;
					}
					////
					var openCard :OpenCard = notification.getBody() as OpenCard;
					Debug.echo("NineHalf---》open card res:"+openCard.pokers,Debug.TRACER);
					this.sendNotification(NineHalfMediator.NineHalf_OpenCard,openCard);
					break;
				}
				case NineHalfProxy.Balance_Result://结算
				{
					///
					if(AppData.getInstance().user.gameStatus == GameStatus.GameStart)
					{
						AppData.getInstance().user.isShowBalance = false;
					}
					///
					AppData.getInstance().user.gameStatus = GameStatus.GameEnd;
					////
					var result :NineHalfResult = notification.getBody() as NineHalfResult;
					Debug.echo("NineHalf---》balance res : "+result,Debug.TRACER);
					this.sendNotification(NineHalfMediator.NineHalf_Balance,result);
					break;
				}
				case ApplicationConstants.NineHalf_ChangeTable://换桌
				{
					Debug.echo("NineHalf---》change table res",Debug.TRACER);
					///初始化桌子信息
					AppData.getInstance().nineHalfGame.nineHalfPlayers = [];
					nineHalfProxy.changeTable(userId);
					break;
				}
				case ApplicationConstants.NineHalf_ContinueGame://继续游戏
				{
					Debug.echo("NineHalf---》continue game req",Debug.TRACER);
					nineHalfProxy.continueGame(userId);
					break;
				}
				case NineHalfProxy.NineHalf_ContinueGame_Result://继续游戏结果
				{
					Debug.echo("NineHalf---》continue game res",Debug.TRACER);
					break;
				}
				case NineHalfProxy.NineHalf_LeaveGame_Result://离开游戏结果
				{
					pos = notification.getBody() as int;
					Debug.echo("NineHalf---》leave game pos = "+pos,Debug.TRACER);
					AppData.getInstance().nineHalfGame.removePlayerByPos(pos);
					this.sendNotification(NineHalfMediator.NineHalf_LeaveGame,pos);
					break;
				}
				case ApplicationConstants.NineHalf_GiveUpHost://下庄
				{
					Debug.echo("NineHalf---》give up host req",Debug.TRACER);
					nineHalfProxy.giveUpHost(userId);
					break;
				}
				case NineHalfProxy.NineHalf_GiveupHost_Result://下庄结果
				{
					pos = notification.getBody() as int;
					Debug.echo("NineHalf---》give up host res pos = "+pos,Debug.TRACER);
					this.sendNotification(NineHalfMediator.NineHalf_GiveUpHost,pos);
					break;
				}
				case ApplicationConstants.NineHalf_Chat://聊天
				{
					//chat = notification.getBody() as Chat;
					//Debug.echo("NineHalf---》chat req",Debug.TRACER);
					//nineHalfProxy.chatSaying(userId,chat.contents);
					break;
				}
				case NineHalfProxy.NineHalf_Chat_Result://聊天结果
				{
					//chat = notification.getBody() as Chat;
					//Debug.echo("NineHalf---》chat res pos = "+chat.tablePos+" content: "+chat.sayContent,Debug.TRACER);
					//this.sendNotification(NineHalfMediator.NineHalf_Chat,chat);
					break;
				}
				case NineHalfProxy.GameEnd_Result://结束
				{
					AppData.getInstance().user.gameStatus = GameStatus.GameEnd;
					//
					var gameEnd :GameEnd = notification.getBody() as GameEnd;
					Debug.echo("NineHalf---》game end " + gameEnd,Debug.TRACER);
					this.sendNotification(NineHalfMediator.NineHalf_GameEnd,gameEnd);
					///
					AppData.getInstance().user.isShowBalance = true;
					this.sendNotification(NotificationConstants.Server_GetUserFortune_Success);
					break;
				}
				case ApplicationConstants.NineHalf_Interactive://交互
				{
					//interactiveData = notification.getBody() as InteractiveData;
					//Debug.echo("NineHalf---Interactive req " + interactiveData,Debug.TRACER);
					//nineHalfProxy.interactive(userId,interactiveData.targetId,interactiveData.itemId);
					break;
				}
				case NineHalfProxy.Interactive_Result://交互结果
				{
					//interactiveData = notification.getBody() as InteractiveData;
					//Debug.echo("NineHalf---Interactive res " + interactiveData,Debug.TRACER);
					//this.sendNotification(NineHalfMediator.NineHalf_Interactive,interactiveData);
					break;
				}
			}
		}
	}
}